<extend name="Layout:layout_list" />
<block name="body_before_block">    
    <script src="__THEME__Plugin/ajax_load_options.min.js" type="text/javascript"></script>
</block>
<block name="body_content_block">
    <form action="{:AddonU('CtiTester/queue_opt_save')}" method="post">
        <ul>
            <if condition="$isSuperAdmin">
                <label>租户ID：</label><select name="siteID" title="请选择租户" data-url="{:AddonU('Admin/get_admin_json')}"></select>
                <else/>
                <li style="display: none;"><input type="hidden" name="siteID" value="{$loginData.siteID}"/></li>
            </if>
            <li>
                <label>队列名称：</label>
                <select name="queue1" title="请选择队列名称" data-url="{:AddonU('Queue/get_queue_json','siteID=varid')}"></select>
                <input type="text" name="queue" placeholder="队列号" required/>
            </li>
            <li>
                <label>分机名称：</label>
                <select id="extension-picker" title="请选择分机名称" data-url="{:AddonU('Extension/get_extension_json','siteID=varid')}"></select>
                <input type="text" name="extension" placeholder="分机号,多个分机以英文逗号隔开" size="45" required/>
            </li>
            <li>
                <label>操作：</label>
                <select name="opt" title="请选择操作" required>
                    <option>请选择操作</option>
                    <option value="login">签入</option>
                    <option value="loginout">签出</option>
                    <option value="idle">示闲</option>
                    <option value="busy">示忙</option>
                    <option value="trans">转接</option>
                    <option value="hangup">挂断</option>
                    <option value="monitor">监听</option>
                </select>
            </li>
            <li>
                <input type="submit" value="保存"/> <a href="{:AddonU('CtiTester/index')}" class="easyui-linkbutton">返回</a>
            </li>
        </ul>
    </form>
</block>
<block name="body_after_block">
<script type="text/javascript">
    ajax_load_options({selector:'select[name="siteID"]', def_option: '选择租户', func: afterSiteID});
    afterSiteID();
    function afterSiteID() {
        var val = $('select[name="siteID"]').val();
        if (!val) {
            val = '{$loginData.siteID}';
        }
        ajax_load_options({selector:'select[name="queue1"]', url:$('select[name="queue1"]').data('url').replace('varid',val), def_option: '选择队列号码'});
        ajax_load_options({selector:'#extension-picker', url:$('#extension-picker').data('url').replace('varid',val),def_option:  '请选择分机名称'});
    }
    $('select[name="siteID"]').change(function () {
        afterSiteID();
    })
    $('select[name="queue1"]').change(function () {
        $('input[name="queue"]').val($(this).val());
    })
    $('#extension-picker').change(function () {
        $('input[name="extension"]').val($(this).val());
    })
</script>
</block>